package com.coolingme.springframework.aop.aspect;

import com.coolingme.springframework.aop.intercept.MeMethodInterceptor;
import com.coolingme.springframework.aop.intercept.MeMethodInvocation;

import java.lang.reflect.Method;

/**
 * @author wangyue
 * @date 2024/09/10 22:15
 */
public class MeMethodBeforeAdviceInterceptor extends MeAbstractAspectJAdvice implements MeMethodInterceptor {
    private MeJoinPoint jp;

    public MeMethodBeforeAdviceInterceptor(Object aspect, Method adviceMethod) {
        super(aspect, adviceMethod);
    }

    public void before(Method method, Object[] arguments, Object aThis) throws Throwable {
        invokeAdviceMethod(this.jp, null, null);
    }

    @Override
    public Object invoke(MeMethodInvocation mi) throws Throwable {
        jp = mi;
        this.before(mi.getMethod(), mi.getArguments(), mi.getThis());
        return mi.proceed();
    }

}
